angular.module('mamApp').controller('planAlbumsController', ['$scope', 'PlayControlManager', '$state', '$uibModal',
    function ($scope, PlayControlManager, $state, $uibModal) {
        var planId=$state.params.planId;

        $scope.fileNames=[{key:"",value:"查询字段"},{key:"albumId",value:"专辑ID"},{key:"albumName",value:"专辑名称"}];


        $scope.search = {
            pageNo: $state.params.pageNo || 1,
            pageSize: $state.params.pageSize || 10,
            key:$state.params.key||"",
            value:$state.params.value
        };


        $scope.findData=function () {
            $scope.search.pageNo=1;
            $state.go($state.current.name,$scope.search)
        }
        $scope.paginationConf = {
            currentPage: $state.params.pageNo || 1,
            itemsPerPage: $state.params.pageSize || 10,
            pagesLength: 9,
            search: 0,
            onChange: function () {
                $scope.search.pageNo = this.currentPage;
                $scope.search.pageSize = this.itemsPerPage;
                $state.go($state.current.name, $scope.search)
            }
        }
        $scope.allCheckChange = function (allChecked) {
            $scope.albums.forEach(function (item) {
                item.checked = allChecked;
            })
        }

        $scope.albumCheckChange = function (album) {
            $scope.allChecked = true;
            $scope.albums.forEach(function (item) {
                if (!item.checked) {
                    $scope.allChecked = false;

                }
            })
        }


        


        PlayControlManager.albumListByPlanId(planId,[$scope.search.pageNo, $scope.search.pageSize],$scope.search).then(function (result) {
            $scope.albums = result.data.pageList;
            $scope.paginationConf.totalItems = result.data.total;
        })


        //调整专辑的播控方案多个
        $scope.adjustAlbumPlan=function () {
            var ids = [];
            $scope.albums.forEach(function (item) {
                if (item.checked) {
                    ids.push(item.albumId)
                }
            })
            if (!ids.length) {
                return false;
            }
            var modal = $uibModal.open({
                templateUrl: 'adjustAlbumPlan.html',
                controller: 'adjustAlbumPlanModalController',
                size: 'normal',
                resolve: {
                    param: function () {
                        return {ids: ids}
                    }
                }
            });
            modal.result.then(function (result) {
                if (result == "ok") {
                    setTimeout(function () {
                        $state.reload();
                    }, 200)
                }
            });
        }
        //调整专辑的播控方案单个
        $scope.adjustAlbumPlanOne=function (id) {

            var modal = $uibModal.open({
                templateUrl: 'adjustAlbumPlan.html',
                controller: 'adjustAlbumPlanModalController',
                size: 'normal',
                resolve: {
                    param: function () {
                        return {ids: [id]}
                    }
                }
            });
            modal.result.then(function (result) {
                if (result == "ok") {
                    setTimeout(function () {
                        $state.reload();
                    }, 200)
                }
            });
        }




    }])

